<template>
  <div class="login-card">
    <!-- 顶部的标题 -->
    <div class="title">硅谷甄选运营平台</div>
    <!-- 中间的tabs切换 -->
    <div class="content">
      <div class="tabs">
        <el-tabs type="border-card" stretch v-model="activeName">
          <!-- 1.账号登录的Pane -->
          <el-tab-pane name="account">
            <template #label>
              <div class="label">
                <el-icon><UserFilled /></el-icon>
                <span class="text">帐号登录</span>
              </div>
            </template>
            <pane-account ref="accountRef" @loadingClick="loadingChange" />
          </el-tab-pane>
          <!-- 2.手机登录的Pane -->
          <el-tab-pane name="phone">
            <template #label>
              <div class="label">
                <el-icon><Cellphone /></el-icon>
                <span class="text">手机登录</span>
              </div>
            </template>
            <pane-phone />
          </el-tab-pane>
        </el-tabs>
      </div>
    </div>
    <!-- 底部区域 -->
    <div class="controls">
      <el-checkbox v-model="isRemPwd" label="记住密码" size="large" />
      <el-link type="primary" href="#/login" target="_blank">忘记密码</el-link>
    </div>
    <div class="login-btn">
      <el-button type="primary" :loading="loading" size="large" @click="handleLoginBtnClick"> 立即登录 </el-button>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, watch } from 'vue'
import PaneAccount from './pane-account.vue'
import PanePhone from './pane-phone.vue'
import { ElMessage } from 'element-plus'
import { localCache } from '@/utils/cache'

const activeName = ref('account')
const isRemPwd = ref<boolean>(localCache.getCache('isRemPwd') ?? false)
watch(isRemPwd, (newValue) => {
  if (newValue) {
    localCache.setCache('isRemPwd', newValue)
  } else {
    localCache.removeCache('isRemPwd')
  }
})
const accountRef = ref<InstanceType<typeof PaneAccount>>()
//定义变量控制按钮加载效果
const loading = ref(false)

function handleLoginBtnClick() {
  if (activeName.value === 'account') {
    accountRef.value?.loginAction(isRemPwd.value)
  } else {
    ElMessage.error('正在开发中...')
  }
}
const loadingChange = (val: boolean) => {
  loading.value = val
}
</script>

<style lang="scss" scoped>
.login-card {
  width: 480px;
  border-radius: 20px;
  box-shadow: 0 0 10px #dcdfe6;
  background-color: #ffffff;
  background: url('@/assets/images/login_form.png') no-repeat;
  background-size: cover;
  z-index: 1;
  .title {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100px;
    font-size: 40px;
    color: #fff;
  }
  .content {
    padding: 0px 50px;
    .label {
      display: flex;
      align-items: center;
      justify-content: center;
      .text {
        margin-left: 5px;
      }
    }
  }
  .controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 50px;
  }
  .login-btn {
    width: 100%;
    padding: 0 50px 30px;
    .el-button {
      width: 100%;
      // --el-button-size: 50px;
    }
  }
}
</style>
